import { Component } from '@angular/core';
import { Student } from './model/student';
import { StudentService } from './service/student.service';
import { StudentVo } from './vo/student-vo';




@Component({
  selector: 'app-root',
  templateUrl: './app.component.html',
  styleUrls: ['./app.component.css']
})
export class AppComponent {
  title = '大学';
//变量类型声明
  textvalue:string;
  numbervalue:number;

  student:Student;
  sl:Array<Student>;

  studentvo:StudentVo;


  constructor(private studentservice:StudentService)
  {}









//初始化方法
ngOnInit() {
//变量的初始化
this.textvalue='今天天气很好';
this.numbervalue=58+76;
this.studentvo=new StudentVo();

this.student=new Student();
this.sl=new Array();

this.loadStudentList();

// this.student.name="测试姓名"
// this.student.sex="男";
// this.student.birthday=new Date().getTime();





}


//添加事件

add(){

console.dir(this.studentvo);

this.studentservice.addStudentInfo(this.studentvo)
.then((data:any)=>{
//请求事件完成后
this.loadStudentList();


})


}



//从服务器端加载多行数据

loadStudentList(){

  this.studentservice.getStudentList()
  .then((data:any)=>{
   this.sl=data;


  })


}


//通过对象的主键获取单个Student对象
   
getToUpdateStudent(id:string){

this.studentservice.getSingleStudentById(id)
.then((data:Student)=>{
this.studentvo=new StudentVo();
this.studentvo.studentid=data.studentid;
this.studentvo.xh=data.stunum;
this.studentvo.xm=data.name;

})

}

//删除单个对象

delteStudent(id:string){

this.studentservice.deleteStudent(id)
.then((flag:boolean)=>{
if(flag==true){
  this.loadStudentList();
}
else{
  alert("操作异常，请刷新后重试");
}


})

}







}
